home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 1 / Amiga Tools.iso / wb-tools / toolmanager / source / library / soundobj.c < prev    next >
C/C++ Source or Header  |  1994-06-06  |  5KB  |  187 lines

  1. /*
  2.  * soundobj.c  V2.1
  3.  *
  4.  * TMObject, Type: Sound
  5.  *
  6.  * (c) 1990-1993 Stefan Becker
  7.  */
  8.  
  9. #include "ToolManagerLib.h"
  10.  
  11. /* extended TMObject structure for TMOBJTYPE_SOUND objects */
  12. struct TMObjectSound {
  13.                       struct TMObject  so_Object;
  14.                       char            *so_Command;
  15.                       char            *so_Port;
  16.                       char            *so_ARexxCmd;
  17.                       ULONG            so_CmdLen;
  18.                      };
  19.  
  20. /* Create a Sound object */
  21. struct TMObject *CreateTMObjectSound(struct TMHandle *handle, char *name,
  22.                                      struct TagItem *tags)
  23. {
  24.  struct TMObjectSound *tmobj;
  25.  
  26.  /* allocate memory for object */
  27.  if (tmobj=(struct TMObjectSound *)
  28.             AllocateTMObject(sizeof(struct TMObjectSound))) {
  29.   struct TagItem *ti,*tstate;
  30.  
  31.   /* Set object defaults */
  32.   tmobj->so_Port=DefaultPortName;
  33.   tmobj->so_Command=DefaultNoName;
  34.  
  35.   /* Scan tag list */
  36.   tstate=tags;
  37.   while (ti=NextTagItem(&tstate)) {
  38.  
  39.    DEBUG_PRINTF("Got Tag (0x%08lx)\n",ti->ti_Tag);
  40.  
  41.    switch (ti->ti_Tag) {
  42.     case TMOP_Command: {
  43.                         char *s=(char *) ti->ti_Data;
  44.                         if (s) tmobj->so_Command=s;
  45.                        }
  46.                        break;
  47.     case TMOP_Port:    {
  48.                         char *s=(char *) ti->ti_Data;
  49.                         if (s) tmobj->so_Port=s;
  50.                        }
  51.                        break;
  52.    }
  53.   }
  54.  
  55.   /* Calculate command line length */
  56.   tmobj->so_CmdLen=15+strlen(tmobj->so_Port)+strlen(tmobj->so_Command);
  57.  
  58.   /* Get memory for command line */
  59.   if (tmobj->so_ARexxCmd=AllocMem(tmobj->so_CmdLen+1,MEMF_PUBLIC)) {
  60.    char *cp=tmobj->so_ARexxCmd;
  61.  
  62.    /* Build ARexx command */
  63.    strcpy(cp,"'address \"");
  64.    strcat(cp,tmobj->so_Port);
  65.    strcat(cp,"\" \"");
  66.    strcat(cp,tmobj->so_Command);
  67.    strcat(cp,"\"'");
  68.  
  69.    /* All OK */
  70.    return(tmobj);
  71.   }
  72.   FreeMem(tmobj,sizeof(struct TMObjectSound));
  73.  }
  74.  
  75.  /* call failed */
  76.  return(NULL);
  77. }
  78.  
  79. /* Delete a Sound object */
  80. BOOL DeleteTMObjectSound(struct TMObjectSound *tmobj)
  81. {
  82.  DEBUG_PRINTF("Delete/Sound (0x%08lx)\n",tmobj);
  83.  
  84.  /* Remove links */
  85.  DeleteAllLinksTMObject((struct TMObject *) tmobj);
  86.  
  87.  /* Remove object from list */
  88.  Remove((struct Node *) tmobj);
  89.  
  90.  /* Free resources */
  91.  FreeMem(tmobj->so_ARexxCmd,tmobj->so_CmdLen+1);
  92.  
  93.  /* Free object */
  94.  FreeMem(tmobj,sizeof(struct TMObjectSound));
  95.  
  96.  /* All OK. */
  97.  return(TRUE);
  98. }
  99.  
  100. /* Change a Sound object */
  101. struct TMObject *ChangeTMObjectSound(struct TMHandle *handle,
  102.                                      struct TMObjectSound *tmobj,
  103.                                      struct TagItem *tags)
  104. {
  105.  struct TagItem *ti,*tstate;
  106.  char *oldcmd,*oldport,*oldline;
  107.  ULONG oldlen;
  108.  
  109.  /* Scan tag list */
  110.  tstate=tags;
  111.  while (ti=NextTagItem(&tstate)) {
  112.  
  113.   DEBUG_PRINTF("Got Tag (0x%08lx)\n",ti->ti_Tag);
  114.  
  115.   switch (ti->ti_Tag) {
  116.    case TMOP_Command: {
  117.                        char *s=(char *) ti->ti_Data;
  118.                        oldcmd=tmobj->so_Command;
  119.                        if (s) tmobj->so_Command=s;
  120.                       }
  121.                       break;
  122.    case TMOP_Port:    {
  123.                        char *s=(char *) ti->ti_Data;
  124.                        oldport=tmobj->so_Port;
  125.                        if (s) tmobj->so_Port=s;
  126.                       }
  127.                       break;
  128.   }
  129.  }
  130.  
  131.  /* Get old command line parameters */
  132.  oldline=tmobj->so_ARexxCmd;
  133.  oldlen=tmobj->so_CmdLen;
  134.  
  135.  /* Calculate command line length */
  136.  tmobj->so_CmdLen=15+strlen(tmobj->so_Port)+strlen(tmobj->so_Command);
  137.  
  138.  /* Calculate command line length */
  139.  if (tmobj->so_ARexxCmd=AllocMem(tmobj->so_CmdLen+1,MEMF_PUBLIC)) {
  140.   char *cp=tmobj->so_ARexxCmd;
  141.  
  142.   /* Free old command line */
  143.   FreeMem(oldline,oldlen+1);
  144.  
  145.   /* Build ARexx command */
  146.   strcpy(cp,"'address \"");
  147.   strcat(cp,tmobj->so_Port);
  148.   strcat(cp,"\" \"");
  149.   strcat(cp,tmobj->so_Command);
  150.   strcat(cp,"\"'");
  151.  
  152.   /* All OK */
  153.   return(TRUE);
  154.  }
  155.  
  156.  /* call failed */
  157.  tmobj->so_Command=oldcmd;
  158.  tmobj->so_Port=oldport;
  159.  tmobj->so_ARexxCmd=oldline;
  160.  tmobj->so_CmdLen=oldlen;
  161.  return(FALSE);
  162. }
  163.  
  164. /* Allocate & Initialize a TMLink structure */
  165. struct TMLink *AllocLinkTMObjectSound(struct TMObjectSound *tmobj)
  166. {
  167.  struct TMLink *tml;
  168.  
  169.  /* Allocate memory for link structure */
  170.  if (tml=AllocMem(sizeof(struct TMLink),MEMF_CLEAR|MEMF_PUBLIC))
  171.   /* Initialize link structure */
  172.   tml->tml_Size=sizeof(struct TMLink);
  173.  
  174.  return(tml);
  175. }
  176.  
  177. /* Activate a Sound object */
  178. void ActivateTMObjectSound(struct TMLink *tml)
  179. {
  180.  struct TMObjectSound *tmobj=(struct TMObjectSound *) tml->tml_Linked;
  181.  
  182.  DEBUG_PRINTF("Activate/Sound\n");
  183.  
  184.  /* Send ARexx command */
  185.  SendARexxCommand(tmobj->so_ARexxCmd,tmobj->so_CmdLen);
  186. }
  187.